package com.lianjinsu.shop.controller;

import com.lianjinsu.shop.controller.vo.Response;
import com.lianjinsu.shop.controller.vo.SelfStatus;
import com.lianjinsu.shop.entity.User;
import com.lianjinsu.shop.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping(value = "Noerify")
public class UserController {

    private final UserService userService;

    @GetMapping("receiveCode/{code}")
    Response<SelfStatus> receiveCode(@PathVariable String code) {
        return Response.ok(userService.session(code));
    }

    @PostMapping("login")
    Response<Object> login(@RequestBody Object object) {
        return Response.ok(object);
    }

    @GetMapping("getUserInfo")
    Response<User> getUserInfo(@RequestParam String openId) {
        return Response.ok(userService.user(openId));
    }

    @GetMapping("setUserInfo")
    Response<Object> setUserInfo(String field, Object value, String openId) {
        return Response.ok(userService.updateUser(field, value, openId));
    }

    @GetMapping("setUserOnlineStatus")
    Response<Object> setUserOnlineStatus(int isOnline, String openId) {
        return Response.ok(userService.updateUser("is_online", isOnline, openId));
    }
}
